package com.blood.modules.pregnancy.controller;

import com.blood.core.annotation.Idempotent;
import com.blood.core.resp.GlobalResultStatus;
import com.blood.core.resp.PageResult;
import com.blood.core.resp.ResponseResult;
import com.blood.core.util.bean.ListUtils;
import com.blood.modules.pregnancy.dto.req.PregnancyGatherUserPageReq;
import com.blood.modules.pregnancy.dto.req.PregnancyUserPageReq;
import com.blood.modules.pregnancy.dto.req.PregnancyUserReq;
import com.blood.modules.pregnancy.dto.req.PregnancyUserSaveReq;
import com.blood.modules.pregnancy.dto.resp.PregnancyGatherUserPageResp;
import com.blood.modules.pregnancy.dto.resp.PregnancyUserInfoResp;
import com.blood.modules.pregnancy.dto.resp.PregnancyUserListResp;
import com.blood.modules.pregnancy.dto.resp.PregnancyUserPageResp;
import com.blood.modules.pregnancy.service.IPregnancyUserService;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 孕产用户Controller
 *
 * @author daoren
 * @date 2022-11-24 11:36:34
 */
@Api(value = "孕产管理", tags = "孕产管理")
@ApiSort(902)
@RestController
@RequestMapping("/pregnancy/user")
public class PregnancyUserController {

    /**
     * 孕产用户服务.
     */
    @Autowired
    private IPregnancyUserService pregnancyUserService;

    /**
     * 分页查询列表
     *
     * @param req
     * @return 分页数据
     */
    @PostMapping("/pageList")
    @ApiOperation(value = "孕产用户列表-分页")
    public ResponseResult<PageResult<PregnancyUserPageResp>> pageList(@RequestBody PregnancyUserPageReq req) {
        return pregnancyUserService.pageList(req);
    }

    /**
     * 采集孕产用户列表-分页
     *
     * @param req
     * @return 分页数据
     */
    @PostMapping("/gatherUserPage")
    @ApiOperation(value = "采集孕产用户列表-分页")
    public ResponseResult<PageResult<PregnancyGatherUserPageResp>> gatherUserPage(@RequestBody PregnancyGatherUserPageReq req) {
        return GlobalResultStatus.SUCCESS.toResult().response(pregnancyUserService.gatherUserPageList(req));
    }

    /**
     * 搜索用户.
     *
     * @param req 请求参数
     * @return 列表信息
     */
    @ApiOperation(value = "搜索用户")
    @PostMapping(value = "/search")
    public ResponseResult<List<PregnancyUserListResp>> search(@RequestBody PregnancyUserReq req) {
        return GlobalResultStatus.SUCCESS.toResult().response(ListUtils.copyProperties(pregnancyUserService.queryList(req), PregnancyUserListResp.class));
    }

    /**
     * 添加.
     *
     * @param req 保存参数
     * @return 添加结果
     */
    @ApiOperation(value = "添加孕产用户信息")
    @PostMapping(value = "/add")
    @Idempotent
    public ResponseResult<Void> add(@RequestBody @Validated PregnancyUserSaveReq req) {
        return pregnancyUserService.saveInfo(req);
    }

    /**
     * 修改.
     *
     * @param req 修改参数
     * @return 修改结果
     */
    @ApiOperation(value = "修改孕产用户信息")
    @PostMapping(value = "/update")
    public ResponseResult<Void> update(@RequestBody @Validated PregnancyUserSaveReq req) {
        return pregnancyUserService.updateInfo(req);
    }

    /**
     * 根据id获取详情
     *
     * @param id
     * @return 详情
     */
    @GetMapping("/findDetailById")
    @ApiOperation(value = "获取孕产用户详情")
    public ResponseResult<PregnancyUserInfoResp> findDetailById(@ApiParam(value = "孕妇id", type = "String") @RequestParam("id") String id) {
        return pregnancyUserService.findDetailById(id);
    }
}
